home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Interfaces / CIncludes / fstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-05  |  3.8 KB  |  130 lines  |  [TEXT/MPS ]

  1. /*
  2.     fstream.h -- Streams classes: filebuf, fstreambase, ifstream, ofstream, fstream
  3.     
  4.     Copyright Apple Computer,Inc.    1994-1995
  5.     All rights reserved.
  6.  
  7. */
  8.  
  9. #ifndef __FSTREAM__
  10. #define __FSTREAM__        1
  11.  
  12. #include <iostream.h>
  13.  
  14. #ifdef powerc
  15. #pragma options align=power
  16. #endif
  17.  
  18. class filebuf : public streambuf
  19. {
  20.  
  21. public:
  22.         static const int openprot;      // default protection mode for open
  23.  
  24. public:
  25.                         filebuf();
  26.                         filebuf(int fd);
  27.                         filebuf(int fd, char* p, int l);
  28.                         ~filebuf();
  29.         int             is_open()       { return opened; }
  30.         int             fd()            { return xfd; }
  31.         filebuf*        open(const char *name, int om, int prot = openprot);
  32.         filebuf*        attach(int fd);
  33.         filebuf*        close();
  34.  
  35. public:
  36.         virtual int     overflow(int = EOF);
  37.         virtual int     underflow();
  38.         virtual int     sync();
  39.         virtual streampos seekoff(streamoff, ios::seek_dir, int);
  40.         virtual streambuf* setbuf(char* p, int len);
  41.         virtual int     xsputn(const char* s, int n);
  42.  
  43. protected:
  44.         int             xfd;    
  45.         int             mode;
  46.         char            opened;
  47.         char            i_opened_it;    // If true, the associated file was opened by this object.
  48.         streampos       last_seek;
  49.         char*           in_start;
  50.         int             last_op();
  51.         char            lahead[2];
  52.  
  53. };  // class filebuf
  54.  
  55.  
  56. class fstreambase : virtual public ios
  57. {
  58.  
  59. public:
  60.                         fstreambase();
  61.                         fstreambase(const char* name, int mode, int prot = filebuf::openprot);
  62.                         fstreambase(int fd);
  63.                         fstreambase(int fd, char* p, int l);
  64.                         ~fstreambase();
  65.         void            open(const char* name, int mode, int prot = filebuf::openprot);
  66.         void            attach(int fd);
  67.         void            close();
  68.         void            setbuf(char* p, int l);
  69.         filebuf*        rdbuf()         { return &buf; }
  70.  
  71. private:
  72.         filebuf         buf;
  73.  
  74. protected:
  75.         void            verify(int);
  76.  
  77. };  // class fstreambase
  78.  
  79.  
  80. class ifstream : public fstreambase, public istream
  81. {
  82.  
  83. public:
  84.                         ifstream();
  85.                         ifstream(const char* name, int mode = ios::in, int prot = filebuf::openprot);
  86.                         ifstream(int fd);
  87.                         ifstream(int fd, char* p, int l);
  88.                         ~ifstream();
  89.         void            open(const char* name, int mode = ios::in, int prot = filebuf::openprot);
  90.         filebuf*        rdbuf()         { return fstreambase::rdbuf(); }
  91.  
  92. };  // class ifstream
  93.  
  94.  
  95. class ofstream : public fstreambase, public ostream
  96. {
  97.  
  98. public:
  99.                         ofstream();
  100.                         ofstream(const char* name, int mode = ios::out, int prot = filebuf::openprot);
  101.                         ofstream(int fd);
  102.                         ofstream(int fd, char* p, int l);
  103.                         ~ofstream();
  104.         void            open(const char* name, int mode = ios::out, int prot = filebuf::openprot);
  105.         filebuf*        rdbuf()         { return fstreambase::rdbuf(); }
  106.  
  107. };  // class ofstream
  108.  
  109.  
  110. class fstream : public fstreambase, public iostream
  111. {
  112.  
  113. public:
  114.                         fstream();
  115.                         fstream(const char* name, int mode, int prot = filebuf::openprot);
  116.                         fstream(int fd);
  117.                         fstream(int fd, char* p, int l);
  118.                         ~fstream();
  119.         void            open(const char* name, int mode, int prot = filebuf::openprot);
  120.         filebuf*        rdbuf()         { return fstreambase::rdbuf(); }
  121.  
  122. };  // class fstream
  123.  
  124.  
  125. #ifdef powerc
  126. #pragma options align=reset
  127. #endif
  128.  
  129. #endif    /* __FSTREAM__ */
  130.